from selenium.webdriver.common.by import By

from Utils import TestDriver


class TestHome:
    url = ""
    driver = ""

    def __init__(self):
        self.driver = TestDriver.driver
        self.url = "http://8.155.1.153:8081/home"
        self.driver.get(self.url)

    def TestHomeNotLogin(self):
        #未登录状态下,跳转到登陆界面,验证是不是在登陆界面
        url = self.driver.current_url
        assert (url == "http://8.155.1.153:8081/user/login")
        #添加截图
        TestDriver.getScreenShot()

    def TestHomeLogin(self):
        #登陆状态下,页面元素为: 标题、头像、用户名、创建问卷、创建考试
        # 标题
        self.driver.find_element(By.CSS_SELECTOR,"#sk-layout > div > div > section > div.ant-pro-layout-container > header.ant-layout-header.ant-pro-layout-header.ant-pro-layout-header-fixed-header.ant-pro-layout-header-mix.ant-pro-layout-header-fixed-header-action.ant-pro-layout-header-header > div > div.ant-pro-global-header-logo.ant-pro-global-header-logo-mix > a > h1")
        # 头像
        self.driver.find_element(By.CSS_SELECTOR,"#sk-layout > div > div > section > div.ant-pro-layout-container > header.ant-layout-header.ant-pro-layout-header.ant-pro-layout-header-fixed-header.ant-pro-layout-header-mix.ant-pro-layout-header-fixed-header-action.ant-pro-layout-header-header > div > div.ant-pro-global-header-right-content > div > div > div > span > div > span.ant-avatar.ant-avatar-circle.ant-avatar-image > img")
        # 用户名
        self.driver.find_element(By.CSS_SELECTOR,"#sk-layout > div > div > section > div.ant-pro-layout-container > header.ant-layout-header.ant-pro-layout-header.ant-pro-layout-header-fixed-header.ant-pro-layout-header-mix.ant-pro-layout-header-header > div > div.ant-pro-global-header-right-content > div > div > div > span > div > span:nth-child(2)")
        # 创建问卷
        self.driver.find_element(By.CSS_SELECTOR,"#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div > div.ant-col.ant-col-xs-24.ant-col-sm-24.ant-col-md-24.ant-col-lg-24.ant-col-xl-8 > div > div.ant-card-body > div > a:nth-child(1)")
        # 创建考试
        self.driver.find_element(By.CSS_SELECTOR,"#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div > div.ant-col.ant-col-xs-24.ant-col-sm-24.ant-col-md-24.ant-col-lg-24.ant-col-xl-8 > div > div.ant-card-body > div > a:nth-child(2)")
        # 添加截图
        TestDriver.getScreeShot()